﻿@model LeadMaster.ViewModels.ViewModelContacts

@using (Ajax.BeginForm("CreateWithCompany","Contacts",
    new AjaxOptions {
        InsertionMode=InsertionMode.Replace,
        HttpMethod="POST",
        OnFailure="couldNotSave",
        LoadingElementId="ajax-loader",
        UpdateTargetId = "contactdetails"
    }))
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Add New Contact for @Model.Company.Company</legend>
        @Html.HiddenFor(x => x.Contact.CompanyID)
    
        <div class="leftcolumn">
        
        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Salutation)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Contact.Salutation)
            @Html.ValidationMessageFor(model => model.Contact.Salutation)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Forename)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Contact.Forename, new { @class="largetextbox" })
            @Html.ValidationMessageFor(model => model.Contact.Forename)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Initials)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Contact.Initials)
            @Html.ValidationMessageFor(model => model.Contact.Initials)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Surname)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Contact.Surname, new { @class = "largetextbox" })
            @Html.ValidationMessageFor(model => model.Contact.Surname)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Contact.Title)
            @Html.ValidationMessageFor(model => model.Contact.Title)
        </div>


        </div>

        <div class="rightcolumn">
        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Telephone)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Contact.Telephone, new { @class = "largetextbox" })
            @Html.RadioButtonFor(model => model.Contact.DefaultTelephoneField, "Telephone")
            @Html.ValidationMessageFor(model => model.Contact.Telephone)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Tel2)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Contact.Tel2)
            @Html.RadioButtonFor(model => model.Contact.DefaultTelephoneField, "Tel2")
            @Html.ValidationMessageFor(model => model.Contact.Tel2)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Mobile1)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Contact.Mobile1)
            @Html.RadioButtonFor(model => model.Contact.DefaultTelephoneField, "Mobile1")
            @Html.ValidationMessageFor(model => model.Contact.Mobile1)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Mobile2)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Contact.Mobile2)
            @Html.RadioButtonFor(model => model.Contact.DefaultTelephoneField, "Mobile2")
            @Html.ValidationMessageFor(model => model.Contact.Mobile2)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Contact.Email)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Contact.Email, new { @class = "largetextbox" })
            @Html.ValidationMessageFor(model => model.Contact.Email)
        </div>

        </div>
        <div style="margin-top: 10px; float: right; clear:both;">
            <input type="submit" value="Save" class="bigsubmit" id="contactsubmit"/>
            <input type="button" value="Close" class="bigsubmit contactwithcompany" />
        </div>

    </fieldset>
}


@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

<script type="text/javascript">
    $().ready(function () {

        $(".contactwithcompany").click(function () {
            $("#addcontactdialog").dialog('close');
            $("#companiesadduserdialog").dialog('close');
        });

        $("#contactsubmit").click(function () {
            $("#addcontactdialog").dialog('close');
            $("#companiesadduserdialog").dialog('close');

        });

        function couldNotSave() {
            alert("Sorry, there was a problem saving this contact");
        };
    });
</script>
